<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>物资出借记录列表</title>
    <jsp:include page="/WEB-INF/view/commons/css.jsp" />
</head>
<body >
<div id="main-container" class="container-fluid">
    <form action="appMaterialsLend/dolist" method="post" name="searchForm" id="searchForm" role="form" class="form-horizontal">
            <div class="form-group">
                    <label class="col-sm-1 control-label">单号：</label>
                    <div class="col-md-4">
                                <input type="text" class="form-control" name="lendCode" value="${entity.lendCode}" placeholder="单号">
                    </div>
                    <label class="col-sm-1 control-label">主题：</label>
                    <div class="col-md-4">
                                <input type="text" class="form-control" name="lendTitle" value="${entity.lendTitle}" placeholder="主题">
                    </div>
            </div>
            <div class="form-group">
                    <label class="col-sm-1 control-label">来往单位：</label>
                    <div class="col-md-4">
                        <%-- <input type="text" class="form-control" name="orgName" value="${entity.orgName}" placeholder="来往单位名称"> --%>
                        <select class="selectpicker form-control" name="orgId">
                        	<option value="" selected>--请选择--</option>
                        	<c:forEach var="obj" items="${orgList}" varStatus="i">
                        		<option value="${obj.id}">${obj.orgName}</option>
                        	</c:forEach>
                        </select>
                    </div>
                    <label class="col-sm-1 control-label">发起时间：</label>
                    <div class="col-md-6">
                        <div class="input-group">
                           <input type="text"  class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', maxDate:'#F{$dp.$D(\'endActionTime\')}'})" id="beginActionTime" name="beginActionTime" value="${searchEntity.beginActionTime}" placeholder="开始时间" />
                			至 <input type="text"  class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', minDate:'#F{$dp.$D(\'beginActionTime\')}'})" id="endActionTime" name="endActionTime" value="${searchEntity.endActionTime}" placeholder="结束时间" />
                           <button id="searchBtn" type="button" class="btn btn-sm btn-info" style="margin-left:10px;margin-right: 10px;"><i class="fa fa-search"></i> 搜索</button>
                           <button type="button" data-url="appMaterialsLend/create" class="btn btn-sm btn-success link_add" data-title="新增物资出借记录"><i class="fa fa-plus"></i> 起草 </button>
                        </div>
                    </div>
            </div>

    </form>

    <table id="table_data" class="table table-striped table-bordered table-hover">
        <thead>
        <tr>
            <!-- <th class="center td-checkbox" width="5%">
                <label><input type="checkbox" class="check-all ace" data-tableid="table_data" /><span class="lbl"></span></label>
            </th> -->
            <th width="10%">单号</th>
            <th width="10%">主题</th>
            <th width="10%">来往单位名称</th>
            <th width="10%">经办人</th>
            <th width="10%">发起时间</th>
            <th width="10%">出借状态</th>
            <th width="10%">操作</th>
        </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>
<!-- script start -->
<jsp:include page="/WEB-INF/view/commons/js.jsp" />
<script type="text/javascript">
    $(document).ready(function(e) {
        var table = $("#table_data").dataTable({
            ajax: function(data, callback, settings){
                tableAjax($("#searchForm"),data, callback, settings);
            },
            //列表表头字段
            columns: [
                /* mainConfig.checkboxColumn, */
                { "data": "lendCode",name:"lend_code",orderable:false},
                { "data": "lendTitle",name:"lend_title",orderable:false},
                { "data": "orgName",name:"org_name",orderable:false},
                { "data": "agentName",name:"agent_name",orderable:false},
                { "data": "actionTimeStr",name:"action_time"},
                { "data": "lendStatusStr",name:"lend_status",orderable:false },
                {
                    "data": "action",
                    "render": function ( data, type, row, meta ) {
                    	var A = "<a href='javacript:void(0);' onclick=\"instorage('" + row.id + "');\">出借</a>";
                    	var B = "<a href='javacript:void(0);' onclick=\"handlerReturnDetailShow('" + row.id + "');\">归还</a>";
                    	var C = "<a href='javacript:void(0);' onclick=\"handlerShow('" + row.id + "');\">查看</a>";
                    	var D = "<a href='javacript:void(0);' onclick=\"handlerShowEdit('" + row.id + "');\">编辑</a>";
                   		var E = "<a href='javacript:void(0);' onclick=\"handlerDelete('"+ row.id +"');\">删除</a>";
                       	if(row.lendStatus == 0){
                       		return A + "&nbsp;&nbsp;" + D + "&nbsp;&nbsp;" + E;
                       	}
                       	if(row.lendStatus == 1){
                       		return B + "&nbsp;&nbsp;" +  C;
                       	}
                       	if(row.lendStatus == 2){
                       		return C;
                       	}
                       	return "";
                      },
                      orderable:false
                  }
        	]
    }).api();

        //查询条件
        $("#searchForm").submit(function(){
            table.ajax.reload();
            return false;
        });
    });
    
    // 物资借还查看
    function handlerShow(id){
    	var layerIndex = layer.open({
            title: "物资借还查看",
            type: 2,
            content: "/appMaterialsLend/record/"+ id,
            area: [$(window).width()+"px", $(window).height()+"px"]
        });
    }
    
    //归还物资
    function handlerReturnDetailShow(id){
    	var layerIndex = layer.open({
            title: "归还物资",
            type: 2,
            content: "/appMaterialsLend/returnDetail/"+ id,
            area: [$(window).width()+"px", $(window).height()+"px"]
        });
    }
    
    //编辑
    function handlerShowEdit(id){
    	var layerIndex = layer.open({
            title: "归还物资",
            type: 2,
            content: "/appMaterialsLend/edit/"+ id,
            area: [$(window).width()+"px", $(window).height()+"px"]
        });
    }
    
    // 删除
    function handlerDelete(id){
    	layer.confirm("您确定要删除当前记录信息吗？", function(index) {
            layer.close(index);
            $.ajax({
                url: "appMaterialsLend/delete/" + id,
                type: "DELETE",
                dataType: "json",
                success: function (data) {
                    if(data.success){
                    	$('#searchForm').submit();
                    }else{
                        layer.alert(data.msg);
                    }
                }
            });
        });
    }
    
    function instorage(id){
    	var option={
            url:"appMaterialsLend/lendSign/"+id,
            title:"出借单签署",
            width:'60%',
            height:'90%'
        };
        openIframe(option);
    }
</script>
<!-- script end -->
</body>
</html>